 var shopids = getvl("shopids");
 var s=getvl("s");
$(function(){
	     if(shopids!=''){
	     	  if(s==''){
	     	  		$("#shangjia").html("");
	     	  	$("#shangjia").html("下架");
	     	  	goodsguanlis();
	     	  }else{
	     	  		$(".sell_goods_xia").html("");
	    var sell_goods_xia='<span id="shangjia" onclick="xiajias(1)">上架</span>'+
			'<em onclick="xiajias(2)">删除</em>';
			$(".sell_goods_xia").append(sell_goods_xia);
	     	  	goodsguanlis2();
	     	  }
	     	   
	     }else{
	     	//alert("未传入有效值");
	     }
});
  
var pageNo=1;     
var ss=0;
function goodsguanlis(){
	if(pageNo==1 || pageNo==2 || ss!=0){
		$.ajax({
		url: urlcore + "/api/goods/selectGoodsList?current="+pageNo+"&shopId="+shopids+"&status=1",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				ss=data.data.list.length;
				$.each(data.data.list, function(y,n) {
                    var goodsguanli='<div class="clearfix add_goods">'+
'		<div class="public-xuanze fl public-checkbox">'+
'			<label class="goodsCheck" id="'+n.id+'">'+
'            	<input type="checkbox" name="spCodeId" value="'+n.id+'"/>'+
'            </label>'+
'		</div>'+
'		<div class="clearfix tuwen">'+
'	    	<a href="javascript:void(0);">'+
'		        <div class="tuwen-img fl">'+
'		            <img onerror="errorImg(this)" src="'+n.coverUrl+'" width="75" height="75">'+
'		        </div>'+
'		        <div class="tuwen-wenzi">'+
'		            <h5 class="wuye_h01">'+n.goodsTitle+'</h5>'+
'		            <div class="wuye_div02">&yen;'+n.tradePrice+'-&yen;'+n.getPrice+'</div>'+
'		        </div>'+
'	        </a>'+
'	    </div>'+
'	</div>';
                    $("#goodsguanli").append(goodsguanli);					
				});
            
                 	$(function(){
                 		
	//全选
	$("#AllCheck").on('click',function(){
		var $this = $(this);
		
		if($this.prop('checked')){
			$this.closest('label').addClass('on');	
			$('.J-huodong-shangpin').find('.goodsCheck').addClass('on').find('input').prop({"checked":true});
		}else{
			$this.closest('label').removeClass('on');	
			
			$('.J-huodong-shangpin').find('.goodsCheck').removeClass('on').find('input').prop({"checked":false});
		}	
	});
	
	//单个选择
	$('.J-huodong-shangpin').on('click','.goodsCheck',function(){
		var $this = $(this);
		if($this.find('input').prop('checked')){
			$this.addClass('on');		
		}else{
			$this.removeClass('on');
				
		}
		
		//判断是否已经全部选中
		var flags = true;
		$('.J-huodong-shangpin').find('.goodsCheck').each(function(index, element) {
			(function(element){
				if($(element).find('input').prop('checked') == false){
					flags = false;
					return false;	
				}	
			})(element);
		});
		if(flags){
			$("#AllCheck").prop({"checked":true}).closest('label').addClass('on');	
		}else{
			$("#AllCheck").prop({"checked":false}).closest('label').removeClass('on');		
		}	
	})
	

	/**	
	$(".goodsCheck").click(function() {
	    var goods = $(this).parent().parent(".add_goods").find(".goodsCheck"); //获取本店铺的所有商品
	    var goodsC = $(this).parent().parent(".add_goods").find("regular-checkbox:checked"); //获取本店铺所有被选中的商品
	    if (goods.length == goodsC.length) { //如果选中的商品等于所有商品
	
	        $("#AllCheck").attr('checked', true); //全选按钮被选中
	
	    } else { //如果选中的商品不等于所有商品
	      
	      $("#AllCheck").attr('checked', false); //全选按钮也不被选中
	
	    }
	});
	
	// 点击全选按钮
	$("#AllCheck").click(function() 
		
		alert("关闭");
		
	    if ($(this).attr("checked") == true)  //如果全选按钮被选中
	    	
	    	
	    	
	       $(".regular-checkbox").attr('checked', true); //所有按钮都被选中
	       
	    } else 
	    	
	       $(".regular-checkbox").attr('checked', false); //else所有按钮不全选
	       
	    }
	});
	**/
                 	});
			}
		},
		error:function() {
			alert("error");
		}
	});
		}
}


var pageNo2=1;
var ss2=0;
function goodsguanlis2(){
	if(pageNo2==1 || pageNo2==2 || ss2!=0){
		$.ajax({
		url: urlcore + "/api/goods/selectGoodsList?current="+pageNo2+"&shopId="+shopids+"&status=2",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				ss2=data.data.list.length;
				$.each(data.data.list, function(y,n) {
                    var goodsguanli='<div class="clearfix add_goods">'+
'		<div class="public-xuanze fl public-checkbox">'+
'			<label class="goodsCheck" id="'+n.id+'">'+
'            	<input type="checkbox" name="spCodeId" value="'+n.id+'"/>'+
'            </label>'+
'		</div>'+
'		<div class="clearfix tuwen">'+
'	    	<a href="javascript:void(0);">'+
'		        <div class="tuwen-img fl">'+
'		            <img onerror="errorImg(this)" src="'+n.coverUrl+'" width="75" height="75">'+
'		        </div>'+
'		        <div class="tuwen-wenzi">'+
'		            <h5 class="wuye_h01">'+n.goodsTitle+'</h5>'+
'		            <div class="wuye_div02">&yen;'+n.tradePrice+'-&yen;'+n.getPrice+'</div>'+
'		        </div>'+
'	        </a>'+
'	    </div>'+
'	</div>';
                    $("#goodsguanli").append(goodsguanli);					
				});
            
                 	$(function(){
                 		
	//全选
	$("#AllCheck").on('click',function(){
		var $this = $(this);
		
		if($this.prop('checked')){
			$this.closest('label').addClass('on');	
			$('.J-huodong-shangpin').find('.goodsCheck').addClass('on').find('input').prop({"checked":true});
		}else{
			$this.closest('label').removeClass('on');	
			
			$('.J-huodong-shangpin').find('.goodsCheck').removeClass('on').find('input').prop({"checked":false});
		}	
	});
	
	//单个选择
	$('.J-huodong-shangpin').on('click','.goodsCheck',function(){
		var $this = $(this);
		if($this.find('input').prop('checked')){
			$this.addClass('on');		
		}else{
			$this.removeClass('on');
				
		}
		
		//判断是否已经全部选中
		var flags = true;
		$('.J-huodong-shangpin').find('.goodsCheck').each(function(index, element) {
			(function(element){
				if($(element).find('input').prop('checked') == false){
					flags = false;
					return false;	
				}	
			})(element);
		});
		if(flags){
			$("#AllCheck").prop({"checked":true}).closest('label').addClass('on');	
		}else{
			$("#AllCheck").prop({"checked":false}).closest('label').removeClass('on');		
		}	
	})
	

	/**	
	$(".goodsCheck").click(function() {
	    var goods = $(this).parent().parent(".add_goods").find(".goodsCheck"); //获取本店铺的所有商品
	    var goodsC = $(this).parent().parent(".add_goods").find("regular-checkbox:checked"); //获取本店铺所有被选中的商品
	    if (goods.length == goodsC.length) { //如果选中的商品等于所有商品
	
	        $("#AllCheck").attr('checked', true); //全选按钮被选中
	
	    } else { //如果选中的商品不等于所有商品
	      
	      $("#AllCheck").attr('checked', false); //全选按钮也不被选中
	
	    }
	});
	
	// 点击全选按钮
	$("#AllCheck").click(function() {
		
		alert("关闭");
		
	    if ($(this).attr("checked") == true) { //如果全选按钮被选中
	    	
	    	
	    	
	       $(".regular-checkbox").attr('checked', true); //所有按钮都被选中
	       
	    } else {
	    	
	       $(".regular-checkbox").attr('checked', false); //else所有按钮不全选
	       
	    }
	});
	**/
	
	
                 	});
			}
		},
		error:function() {
			alert("error");
		}
	});
	}
}
















function shangjias(str){
	  var spCodesTemp = "";
	//alert(str)
	  if(str==1){
	  	    spCodesTemp="";
	  	  
      $('input:checkbox[name=spCodeId]:checked').each(function(i){
       if(0==i){
        spCodesTemp = $(this).val();
       }else{
        spCodesTemp += (","+$(this).val());
       }
      });
     //alert(spCodesTemp+"");
               	  	  
        $.ajax({
		url: urlcore + "/api/goods/selcetAllGoodsXJ?str="+spCodesTemp+"&XJ=2",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//alert("下架成功！！！");
				window.location.href = document.referrer
			}
		},
		error:function() {
			alert("error");
		}
	});       	  	  
	  
	  }else{

      spCodesTemp="";
      $('input:checkbox[name=spCodeId]:checked').each(function(i){
       if(0==i){
        spCodesTemp = $(this).val();
       }else{
        spCodesTemp += (","+$(this).val());
       }
      });
     //alert(spCodesTemp+"");
               	  	  
        $.ajax({
		url: urlcore + "/api/goods/selcetAllGoodsXJ?str="+spCodesTemp+"&XJ=3",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//alert("删除成功！！！");
				window.location.href = document.referrer
			}
		},
		error:function() {
			alert("error");
		}
	});       	  	  
               	  	  
               	  	  
	  }
}


function xiajias(str){

	  var spCodesTemp = "";
	
	  if(str==1){
	  	    spCodesTemp="";
	  	  
      $('input:checkbox[name=spCodeId]:checked').each(function(i){
       if(0==i){
        spCodesTemp = $(this).val();
       }else{
        spCodesTemp += (","+$(this).val());
       }
      });
        $.ajax({
		url: urlcore + "/api/goods/selcetAllGoodsXJ?str="+spCodesTemp+"&XJ=0",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				
				window.location.href = document.referrer
			}
		},
		error:function() {
			alert("error");
		}
	});       	  	  
	  
	  }else{

      spCodesTemp="";
      $('input:checkbox[name=spCodeId]:checked').each(function(i){
       if(0==i){
        spCodesTemp = $(this).val();
       }else{
        spCodesTemp += (","+$(this).val());
       }
      });
    
               	  	  
        $.ajax({
		url: urlcore + "/api/goods/selcetAllGoodsXJ?str="+spCodesTemp+"&XJ=3",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//alert("删除成功！！！");
				window.location.href = document.referrer
			}
		},
		error:function() {
			alert("error");
		}
	});       	  	  
               	  	  
               	  	  
	  }
}

